package com.mes.web.controller.yzl;

import com.mes.entity.yzl.Condition;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Sup {

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    public Condition tdSet(Condition condition){
        if(condition.getCustomerName() == null){
            condition.setCustomerName("");
        }else{
            if(condition.getCustomerName().equals("所有客户")){
                condition.setCustomerName("");
            }
        }
        if(condition.getRecent() == 0) {//没有选择最近时间
            if(condition.getBeginDate() == null){
                if(condition.getEndDate() == null){
                    condition.setBeginDate("");
                    condition.setEndDate("");
                }else{
                    condition.setBeginDate("");
                }
            }
        }else{
            Calendar c = Calendar.getInstance();
            c.setTime(new Date());
            condition.setEndDate(sdf.format(c.getTime()));
            //减去n 天 之前的时间
            c.add(Calendar.DATE, -condition.getRecent());
            condition.setBeginDate(sdf.format(c.getTime()));
        }
        return condition;
    }


}
